home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 333_02 / regex.h < prev    next >
C/C++ Source or Header  |  1989-04-06  |  7KB  |  155 lines

  1. /* Definitions for data structures callers pass the regex library.
  2.    Copyright (C) 1985 Free Software Foundation, Inc.
  3.  */
  4.  
  5.  
  6. #ifndef RE_NREGS
  7. #define RE_NREGS 10
  8. #endif
  9.  
  10. /* Number of failure points to allocate space for initially,
  11.  when matching.  If this number is exceeded, more space is allocated,
  12.  so it is not a hard limit.  */
  13.  
  14. #ifndef NFAILURES
  15. #define NFAILURES            80
  16. #endif /* NFAILURES */
  17.  
  18. /* width of a byte in bits */
  19.  
  20. #define BYTEWIDTH            8
  21. #define FASTMAP_SIZE            (1 << BYTEWIDTH)
  22.  
  23. #ifndef SIGN_EXTEND_CHAR
  24. #define SIGN_EXTEND_CHAR(x) (x)
  25. #endif
  26.  
  27. #ifndef Sword /* must be non-zero in some of the tests below... */
  28. #define Sword 1
  29. #endif
  30.  
  31. /* JF for syntax stuff */
  32. /* To add more variable-syntax features, just use more bits.  If we go over 16,
  33.    we probably should make obscure_syntax a long.  (JF: Yes, virgina, there
  34. really are 16 bit machines out there) */
  35. #define RE_NO_BK_PARENS    (1<<0)
  36. #define RE_NO_BK_VBAR    (1<<1)
  37.  
  38. /* This data structure is used to represent a compiled pattern. */
  39.  
  40. struct re_pattern_buffer
  41. {
  42.     char *buffer;    /* Space holding the compiled pattern commands. */
  43.     int allocated;    /* Size of space that  buffer  points to */
  44.     int used;        /* Length of portion of buffer actually occupied */
  45.     char *fastmap;    /* Pointer to fastmap, if any, or zero if none. */
  46.             /* re_search uses the fastmap, if there is one,
  47.                to skip quickly over totally implausible characters */
  48.     char fastmap_accurate;
  49.             /* Set to zero when a new pattern is stored,
  50.                set to one when the fastmap is updated from it. */
  51.     char can_be_null;   /* Set to one by compiling fastmap
  52.                if this pattern might match the null string.
  53.                It does not necessarily match the null string
  54.                in that case, but if this is zero, it cannot.
  55.                2 as value means can match null string
  56.                but at end of range or before a character
  57.                listed in the fastmap.  */
  58. };
  59. typedef struct re_pattern_buffer    REPAT_BUFFER;
  60.  
  61. /* Structure to store "register" contents data in.
  62.  
  63.    Pass the address of such a structure as an argument to re_match, etc.,
  64.    if you want this information back.
  65.  
  66.    start[i] and end[i] record the string matched by \( ... \) grouping i,
  67.    for i from 1 to RE_NREGS - 1.
  68.    start[0] and end[0] record the entire string matched. */
  69.  
  70. struct re_registers
  71. {
  72.     int start[RE_NREGS];
  73.     int end[RE_NREGS];
  74. };
  75. typedef struct re_registers        REREGS;
  76.  
  77. /* These are the command codes that appear in compiled regular expressions, one per byte.
  78.   Some command codes are followed by argument bytes.
  79.   A command code can specify any interpretation whatever for its arguments.
  80.   Zero-bytes may appear in the compiled regular expression. */
  81.  
  82.     /* followed by one byte giving n, and then by n literal bytes       */
  83. #define RECODE_EXACTN            1
  84.     /* fails unless at beginning of line                   */
  85. #define RECODE_BEGLINE            2
  86.     /* fails unless at end of line                       */
  87. #define RECODE_ENDLINE            3
  88.     /* followed by two bytes giving relative address to jump to        */
  89. #define RECODE_JUMP            4
  90.     /* followed by 2 bytes giving rel addr to resume at in case of failure */
  91. #define RECODE_ON_FAILURE_JUMP        5
  92.     /* Throw away latest failure point and then jump to address.       */
  93. #define RECODE_FINALIZE_JUMP        6
  94.     /* Like jump but finalize if safe to do so.  This is used to jump back */
  95.     /* to the beginning of a repeat.  If the command that follows this       */
  96.     /* jump is clearly incompatible with the one at the beginning of the   */
  97.     /* repeat, such that we can be sure that there is no use backtracking  */
  98.     /* out of repetitions already completed, then we finalize.           */
  99. #define RECODE_MAYBE_FINALIZE_JUMP  7
  100.     /* jump, and push a dummy failure point.  This failure point will be   */
  101.     /* thrown away if an attempt is made to use it for a failure.       */
  102.     /* A + construct makes this before the first repeat.           */
  103. #define RECODE_DUMMY_FAILURE_JUMP   8
  104.     /* matches any one character                       */
  105. #define RECODE_ANYCHAR            9
  106.     /* matches any one char belonging to specified set.  First following   */
  107.     /* byte is # bitmap bytes.    Then come bytes for a bit-map saying which */
  108.     /* chars are in.  Bits in each byte are ordered low-bit-first.       */
  109.     /* A character is in the set if its bit is 1.  A character too large   */
  110.     /* to have a bit in the map is automatically not in the set        */
  111. #define RECODE_CHARSET            10
  112.     /* similar but match any character that is NOT one of those specified  */
  113. #define RECODE_CHARSET_NOT        11
  114.     /* starts remembering the text that is matched and stores it in a       */
  115.     /* memory register followed by one byte containing the register number.*/
  116.     /* Register numbers must be in the range 0 through NREGS.           */
  117. #define RECODE_START_MEMORY        12
  118.     /* stops remembering the text that is matched and stores it in a       */
  119.     /* memory register followed by one byte containing the register number.*/
  120.     /* Register numbers must be in the range 0 through NREGS.           */
  121. #define RECODE_STOP_MEMORY        13
  122.     /* match a duplicate of something remembered.  Followed by one byte    */
  123.     /* containing the index of the memory register.               */
  124. #define RECODE_DUPLICATE        14
  125.     /* Succeeds if before dot                           */
  126. #define RECODE_BEFORE_DOT        15
  127.     /* Succeeds if at dot                           */
  128. #define RECODE_AT_DOT            16
  129.     /* Succeeds if after dot                           */
  130. #define RECODE_AFTER_DOT        17
  131.     /* Succeeds if at beginning of buffer                   */
  132. #define RECODE_BEGBUF            18
  133.     /* Succeeds if at end of buffer                       */
  134. #define RECODE_ENDBUF            19
  135.     /* Matches any word-constituent character                   */
  136. #define RECODE_WORDCHAR         20
  137.     /* Matches any char that is not a word-constituent               */
  138. #define RECODE_NOTWORDCHAR        21
  139.     /* Succeeds if at word beginning                       */
  140. #define RECODE_WORDBEG            22
  141.     /* Succeeds if at word end                           */
  142. #define RECODE_WORDEND            23
  143.     /* Succeeds if at a word boundary                       */
  144. #define RECODE_WORDBOUND        24
  145.     /* Succeeds if not at a word boundary                   */
  146. #define RECODE_NOTWORDBOUND        25
  147.     /* Matches any character whose syntax is specified followed by a byte  */
  148.     /* which contains a syntax code, Sword or such like            */
  149. #define RECODE_SYNTAXSPEC        26
  150.     /* Matches any character whose syntax differs from the specified.       */
  151. #define RECODE_NOTSYNTAXSPEC        27
  152.  
  153.  
  154. #define SYNTAX(c)         re_syntax_table[c]
  155.